package cn.com.bocloud.util;

import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class JDBCUtil {
    static String driver;
    static String url;
    static String name;
    static String password;
    static {
        Properties pro = new Properties();
        try {
            pro.load(JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties"));
            driver = pro.getProperty("jdbc.driver");
            url = pro.getProperty("jdbc.url");
            name = pro.getProperty("jdbc.username");
            password = pro.getProperty("jdbc.password");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConn() throws Exception{
        Class.forName(driver);
        Connection conn = DriverManager.getConnection(url,name,password);
        return conn;
    }
    public static void close(Connection conn, Statement st, ResultSet rs){
        try {
            conn.close();
            st.close();
            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
